1. Home
  2. Python
  3. Python Tutorials
  4. Python – Strings

Python – Strings

Python Strings

A string is a sequence of characters and a character is can be a alphabet, digit or symbol.

The Python treated any sequence of character’s enclosed in quotes as a string.

Python treated both single and double quted sequence as string. But in results of any string will be in a single quote only. like:

‘Welcome’

String Concatenation

In Python strings have operation symbols too. Using a plus (+) symbol concatenate two strings. let’s type below example on Python shell.

The result will be same

‘Hello World’

Next, try with some digits enclosed with and without quotes.

Python checks for the types of values, based on that interprets the plus symbol:

Results:

’25’
7

What happen when you try to concatenate string with digits in Python.

You will see a type error message like TypeError: can only concatenate str (not “int”) to str

First you need to change type of int to str, then you can concatenate them.

Result: 7

Triple Quoted String

In Python we can use sngle quote (‘) or double quote (“) to define a type to string. Python also uses triple quote (”’) for defining the multi line string.

Run the below test on Python shell.

Tags ,